package edu.uci.ics.ai.maze.views;

import java.awt.Graphics;
import java.awt.Polygon;

public class Pen {

  private final Graphics g;

  public Pen(Graphics g) {
    this.g = g;
  }

  public void drawLine(int x1, int y1, int x2, int y2) {
    Polygon pgn = new Polygon();
    if (x1 == x2) {
      pgn.addPoint(x1 + 1, y1);
      pgn.addPoint(x2 + 1, y2);
      pgn.addPoint(x2 - 1, y2);
      pgn.addPoint(x1 - 1, y1);
      g.fillPolygon(pgn);
    } else if (y1 == y2) {
      pgn.addPoint(x1, y1 + 1);
      pgn.addPoint(x2, y2 + 1);
      pgn.addPoint(x2, y2 - 1);
      pgn.addPoint(x1, y1 - 1);
      g.fillPolygon(pgn);
    } else if (x1 < x2 && y1 > y2 || x1 > x2 && y1 < y2) {
      pgn.addPoint(x1 + 1, y1 + 1);
      pgn.addPoint(x2 + 1, y2 + 1);
      pgn.addPoint(x2 - 1, y2 - 1);
      pgn.addPoint(x1 - 1, y1 - 1);
      g.fillPolygon(pgn);
    } else if (x1 < x2 && y1 < y2 || x1 > x2 && y1 > y2) {
      pgn.addPoint(x1 - 1, y1 + 1);
      pgn.addPoint(x2 - 1, y2 + 1);
      pgn.addPoint(x2 + 1, y2 - 1);
      pgn.addPoint(x1 + 1, y1 - 1);
      g.fillPolygon(pgn);
    }
  }
}
